package org.zjh.view.game;


import org.zjh.controller.listener.*;

import javax.swing.*;
import java.awt.*;

import static org.zjh.constant.ImageConstant.GAME_MENU_FRAME_IMAGE;

/**
 * 游戏菜单面板
 */
public class GameMenuPanel extends JPanel {
    private JButton gameStartJbt;
    private JButton rankJbt;
    private JButton gameHelpJbt;
    private JButton loginChangeJbt;
    private JButton accountSettingJbt;
    private JButton exitGameJbt;


    public GameMenuPanel() {
        //调用初始化构造方法
        init();
        //调用监听器注册方法
        addListener();

    }


    /**
     * 初始化
     */
    private void init() {
        setLayout(null);
        //创建按钮
        gameStartJbt = new JButton("开始游戏");
        rankJbt = new JButton("排行榜");
        gameHelpJbt = new JButton("游戏帮助");
        loginChangeJbt = new JButton("切换账号");
        accountSettingJbt = new JButton("账号设置");
        exitGameJbt = new JButton("退出游戏");
        //设置按钮属性
        gameStartJbt.setBounds(525, 350, 100, 25);
        rankJbt.setBounds(525, 400, 100, 25);
        gameHelpJbt.setBounds(525, 450, 100, 25);
        loginChangeJbt.setBounds(525, 500, 100, 25);
        accountSettingJbt.setBounds(525, 550, 100, 25);
        exitGameJbt.setBounds(525, 600, 100, 25);
        //按钮添加
        add(gameStartJbt);
        add(rankJbt);
        add(gameHelpJbt);
        add(loginChangeJbt);
        add(accountSettingJbt);
        add(exitGameJbt);
    }

    /**
     * 添加监听器
     */
    private void addListener() {
        accountSettingJbt.addMouseListener(new AccountSettingJbtLis());
        loginChangeJbt.addMouseListener(new LoginChangeJbtLis());
        exitGameJbt.addMouseListener(new ExitGameLis());
        gameStartJbt.addMouseListener(new StartGameJbtLis());
        rankJbt.addMouseListener(new RankJbtListener());
        gameHelpJbt.addMouseListener(new GameHelpJbtLis());
    }


    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(GAME_MENU_FRAME_IMAGE.getImage(), 0, 0, GAME_MENU_FRAME_IMAGE.getIconWidth(), GAME_MENU_FRAME_IMAGE.getIconHeight(), null);
    }


}

